package com.kartoshka.layouts 
{
	import flash.geom.Rectangle;

	import com.kartoshka.core.UIBase;
	import com.kartoshka.interfaces.ILayout;

	import flash.display.DisplayObject;
	import flash.display.DisplayObjectContainer;

	/**
	 * @author Alexander Zats, 2009
	 */
	public class NullLayout implements ILayout
	{
		
		//TODO Should we allow negative width and height? Probably no 
		public function placeChildrens( width : Number, height : Number, target : DisplayObjectContainer, processOnlyVisible : Boolean = true, paddingLeft : Number = 0, paddingTop : Number = 0, paddingRight : Number = 0, paddingBottom : Number = 0 ) : void
		{
			var numChildren : int = target.numChildren;
			var curChild : DisplayObject;
			
			var workingArea : Rectangle = new Rectangle( paddingLeft, paddingTop, width - paddingLeft - paddingRight, height - paddingTop - paddingBottom );
			
			for ( var i : int = 0; i < numChildren ; i++ )
			{
				curChild = target.getChildAt( i );
				
				trace ( "processing child #" + i );
				
				if ( processOnlyVisible && ! curChild.visible ) continue; 

				var curChildAsUIBase : UIBase = curChild as UIBase;
				
				trace ( "is it UIBase?", curChildAsUIBase );
				
				//	If it's not an UIBase, just skip it
				if ( ! curChildAsUIBase ) continue;
				
				trace( curChildAsUIBase.uid );
				
				//lets check for percents width and height
				if ( !isNaN( curChildAsUIBase.percentWidth ) )
				{
					trace ( "percentWidth", curChildAsUIBase.uid );
					var pw : Number = curChildAsUIBase.percentWidth;
					curChild.width = workingArea.width * curChildAsUIBase.percentWidth;
					curChildAsUIBase.percentWidth =  pw;
				}
				if ( !isNaN( curChildAsUIBase.percentHeight ) )
				{
					trace ( "percentHeight", curChildAsUIBase.uid );
					curChild.height = workingArea.height * curChildAsUIBase.percentHeight; 
				}
				
				trace ();
			}
		}
	}
}
